package com.cy.service.impl;

import com.cy.common.ResultResponse;
import com.cy.entity.Courses;
import com.cy.entity.Users;
import com.cy.mapper.CoursesMapper;
import com.cy.service.ICoursesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Aleven
 * @since 2024-12-21
 */
@Service
public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses> implements ICoursesService {

    @Autowired
    private CoursesMapper coursesMapper ;


    //查询全部课程
    @Override
    public List<Courses> FindAllCourses(){ return coursesMapper.FindAllCourses();}

    //根据分类查询课程
    @Override
    public List<Courses> FindCoursesByClass(Courses Category){ return coursesMapper.FindCoursesByClass(Category);}

    //根据条件筛选搜索
    @Override
    public List<Courses> FindByCondition(Courses courses){return coursesMapper.FindByCondition(courses);}

    //增加课程
    @Override
    public ResultResponse insertCourses(@RequestBody Courses courses) throws Exception{
        if (courses.getTitle() == null || courses.getCategory() == null
        || courses.getDescription() == null || courses.getInstructorID() == null){
            return ResultResponse.fail("请把信息输入全");
        }
        int count = coursesMapper.insertCourses(courses);
        return count>0?ResultResponse.success():ResultResponse.fail();
    }

    //修改课程
    @Override
    public  ResultResponse updateCourses(@RequestBody Courses courses) throws Exception{
        if (courses.getTitle() == null || courses.getCategory() == null || courses.getDescription() == null
                || courses.getInstructorID() == null || courses.getCourseID() == null){
            return ResultResponse.fail("请把信息输入全");
        }

        int count = coursesMapper.updateCourses(courses);
        return count>0?ResultResponse.success():ResultResponse.fail();
    }

    //删除课程
    @Override
    public int delCourses(String courseID){return coursesMapper.delCourses(courseID);}



}
